﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;
using System.Net;
using System.Windows.Forms;

namespace FolderTransfer
{
    public class Client
    {
        private string ip;
        private int port;
        private FolderClient folderClient;

        public FolderClient FolderClient
        {
            get { return folderClient; }
        }

        private FormMain formMain;
        public Client(string ip, int port, FormMain formMain)
        {
            this.ip = ip;
            this.port = port;
            this.formMain = formMain;
        }

        private string recvPath;

        public string RecvPath
        {
            get { return recvPath; }
            set { recvPath = value; }
        }
        public void Connect()
        {
            TcpClient tcpClient = new TcpClient(AddressFamily.InterNetwork);
            try
            {
                IPEndPoint ipe = new IPEndPoint(IPAddress.Parse(this.ip), this.port);
                tcpClient.Connect(ipe);
                folderClient = new FolderClient(tcpClient, formMain, this);
            }
            catch
            {
                tcpClient.Close();
                MessageBox.Show("连接服务器失败,可能对方服务器未开启.");
                return;
            }
        }
    }
}
